package com.cg.design.graphicdesignpattern.strategy;

import java.util.Random;

/**
 * 表示“如果这局猜拳获胜，那么下一局也出一样的手势，如果这局输了，那么下一局就随机出手势”这一策略的类
 *
 * @program: LeetCode->WinningStrategy
 * @description: 表示“如果这局猜拳获胜，那么下一局也出一样的手势，如果这局输了，那么下一局就随机出手势”这一策略的类
 * @author: cg
 * @create: 2022-03-24 18:46
 **/
public class WinningStrategy implements Strategy {

    /**
     * 随机数生成器
     */
    private final Random random;

    /**
     * 保存上一局猜拳的输赢结果
     */
    private boolean won = false;

    /**
     * 保存上一局出的手势
     */
    private Hand pervHand;

    public WinningStrategy(int seed) {
        random = new Random(seed);
    }

    @Override
    public Hand nextHand() {
        if (!won) {
            pervHand = Hand.getHand(random.nextInt(3));
        }
        return pervHand;
    }

    @Override
    public void study(boolean win) {
        won = win;
    }
}
